package com.study.modules.saas.controller;

import com.study.Util.CommonResponse;
import com.study.excel.easyexcel.service.ProductExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

/**
 * @Author hupengming
 * @ClassName
 * @Date 2022-11-01 10:41
 * @Version 1.0
 */
@RestController
@RequestMapping("/sa/excel")
public class SaasExcelController {

    @Autowired
    ProductExcelService excelService;


    @PostMapping
    public CommonResponse importFile(@RequestParam MultipartFile file) throws Exception {
        if (Objects.isNull(file)) {
            return CommonResponse.fail("文件为空");
        }
        if(file.getOriginalFilename().indexOf("xls") == -1){
            return CommonResponse.fail("请上传标准cls文件");
        }
        excelService.productExcel(file.getInputStream());
        return CommonResponse.success();
    }

}
